from flask import Blueprint, send_from_directory, current_app
from os import path

bp = Blueprint('files', __name__)


@bp.route('/file/<string:file>')
def get_file(file):
    FILE_DIRECTORY = path.join(current_app.root_path, 'static', 'file')
    file_path = path.join(FILE_DIRECTORY, file)
    if path.exists(file_path) and path.isfile(file_path):
        return send_from_directory(FILE_DIRECTORY, file, as_attachment=True)
    else:
        return "File not found", 404
